package models

import (
	"gorm.io/gorm"
	"hoop_srv/basic/config"
	"time"
)

type Course struct {
	Id         uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	Title      string         `gorm:"column:title;type:varchar(30);comment:课程标题;not null;" json:"title"`              // 课程标题
	TeacherUrl string         `gorm:"column:teacher_url;type:varchar(255);comment:名师头像;not null;" json:"teacher_url"` // 名师头像
	Price      float64        `gorm:"column:price;type:decimal(10, 2);comment:课程价格;not null;" json:"price"`           // 课程价格
	CreatedAt  time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (c *Course) TableName() string {
	return "course"
}
func (c *Course) GetCourse(id int) error {
	return config.DB.Where("id = ?", id).Limit(1).Find(&c).Error
}
func (c *Course) CreateCouse() error { //创建课程
	return config.DB.Create(&c).Error
}
